<template>
    <div class="main">
    <el-tabs type="border-card">
    <el-tab-pane>
        <span slot="label" class="labelcolor">登录密码</span>
        <div class="warnings"><img src="../assets/images/u20001.png" alt="" style="display:inline-block;height:16px;width:16px;margin-right:2px;"><span class="fontstyle">为了您的权益与安全请不要将密码泄露给他人，并且牢记您的新密码</span></div>
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"  label-position="left" class="demo-ruleForm">
        <el-form-item label="当前密码" prop="prepass">
            <el-input v-model.number="ruleForm.prepass"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pass">
            <el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="确认密码" prop="checkPass">
            <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button class="remerber" @click="submitForm('ruleForm')">确定</el-button>
        </el-form-item>
        </el-form>
    </el-tab-pane>
    </el-tabs>
    </div>
</template>
<script>
  export default {
    data() {
    //检查输入的当前密码是否与正确密码一致
      var checkSame = (rule, value, callback) => {
        if (!value) {
          return callback(new Error('密码错误！'));
        }
      };

      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'));
        } else {
          if (this.ruleForm.checkPass !== '') {
            this.$refs.ruleForm.validateField('checkPass');
          }
          callback();
        }
      };
      var validatePass2 = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.pass) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
      return {
        ruleForm: {
          pass: '',
          checkPass: '',
          prepass: ''
        },
        rules: {
          pass: [
            { validator: validatePass, trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass2, trigger: 'blur' }
          ],
          prepass: [
            { validator: validatePass, trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('submit!');
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      }
    }
  }
</script>
<style src="../style/mine.css">
</style>